﻿using System.Dynamic;
using System.Xml;

namespace P7DC.Common.Parser
{
	public class DynamicXML<T> : DynamicObject
		where T : XmlNode
	{
		private readonly T _instance;

		public DynamicXML(T instance)
		{
			_instance = instance;
		}

		public override bool TrySetMember(SetMemberBinder binder, object value)
		{
			if (_instance.Name == binder.Name)
			{
				_instance.Value = (string)value;
				return true;
			}

			return false;
		}

		public override bool TryGetMember(GetMemberBinder binder, out object result)
		{
			if (_instance.Name == binder.Name)
			{
				result = _instance;
				return true;
			}

			result = null;
			return false;
		}
	}
}
